<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
 <%@ page import="java.util.List" %>
<%@ page import="model.leave_message"%>
<%@ page import="dao.LeaveDao"%>     
<%
	//检查会话中是否有 "student" 属性
	Object fdyObj = session.getAttribute("student");
	if (fdyObj == null) {
	    response.sendRedirect("Login.jsp");
	    return;
	}
%>
    
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>学生页面</title>
<link href="../css/Utils.css" rel="stylesheet" type="text/css" />
<link href="../css/List.css" rel="stylesheet" type="text/css" />

<!-- 退出登录专用 -->
    <script type="text/javascript" src="Loginout.js"></script>
</head>
<body>

<!-- 头部 -->
<div class="header" ><br>
<nerong>&nbsp;&nbsp;学生页面&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;</nerong>

 <button onclick="confirmLogout('<%= (String)session.getAttribute("student") %>','student')">退出登录</button>

</div><br>

<div class="left" >
<table width="80%" height="80%">
<th>
<nerong>学生可选择内容</nerong>

</th>

<tr>
<td>

<a href="../View_Msg/msgStudent.jsp">&emsp;个人信息</a><br>
</td>
</tr>


<tr>
<td>
<a href="../View_SuShe/SuSheStudent.jsp">&emsp;宿舍信息</a><br>
</td>
</tr>

<tr>
<td>
<a href="../View_fix/StudentFix.jsp">&emsp;宿舍报修</a><br>
</td>
</tr>


<tr>
<td>
<a href = "../View_WeiGui/WeiGuiStudent.jsp">&emsp;违规消息查询</a><br>
</td>
</tr>

<tr>
<td>
<a href = "../View_leave/S_Main_Leave.jsp">&emsp;请假</a><br>
</td>
</tr>


</table>

</div>



<div class="context" >
<!-- 这部分是每个大功能的小功能 -->
   <h2>学生请假主页面</h2>
   
   <p style="text-align: center;"><button class="btn" style="background-color: #9FE2BF;color: black;"   onclick="window.location.href='S_add_leave.jsp'"><i class="icon-eye"></i> 新增请假申请</button></p>
   
    <table class="Alltable">
        <tr>
        	<th>编号</th>
        	<th>姓名</th>
            <th>请假时间</th>
            <th>课程</th>
            <th>状态</th>
            <th>操作</th>
            
        </tr>
        <%        
        request.setCharacterEncoding("UTF-8");
        LeaveDao dao = new LeaveDao();
        //获取当前的id
        String id=(String)session.getAttribute("student");
       
        //调用根据id查信息的getAloneLeaveMessages
        List<leave_message> Messages = dao.getAloneLeaveMessages(id);                   
                      
         // 检查leaveMessages列表是否不为null
            if (Messages != null) {
            	// 遍历leaveMessages列表中的每个leave_message对象
                for (leave_message lm : Messages) {
        %>
            <tr>           
            	<td><%= lm.getNumber() %></td>
            	<td><%= lm.getName() %></td>
				<td><%= lm.getSdata() %> <%= lm.getEdata() %></td>
				<td><%= lm.getCourse() %></td>
                <td><%= lm.getStatus() %></td>                
                <td>
                	<button class="btn btn-green" onclick="window.location.href='S_check.jsp?number=<%= lm.getNumber() %>'">
                		<i class="icon-eye"></i> 查看
                	</button>
                	<button class="btn" style="background-color: rgb(255, 128, 0);" onclick="window.location.href='S_delete_leave.jsp?number=<%= lm.getNumber() %>'">
    					<i class="icon-cancel"></i> 撤回
					</button>              	
                </td>
            </tr>
        <%
                }
            } else {
        %>
            <tr>
                <td colspan="4">No leave messages found</td>
            </tr>
        <%
            }
        %>
    </table>
    <!-- 如果有错误信息，显示它 -->
    <%
        String error = (String) request.getAttribute("error");
        if (error != null) {
    %>
        <p style="color:red"><%= error %></p>
    <%
        }
    %>



</div>

	
</body>
</html>